/**
 * Hud
 * Template of hud entity
 **/
var Hud = function() {
	this.cooldown = [];

	// CORE ---
		this.init = function() {
			log('*** INIT HUD ***');

			for (var iE = 0, c = game.mSpell.spells.length; iE < c; iE++) {
				var img = path.spells.small + SpellConf.previewIcons[game.mSpell.spells[iE].icon];
				game.mSpell.spells[iE].img = IM.getInstance(getIMName(img));
				this.cooldown[iE] = null;
			}
		}

		this.update = function() {
			input.listen();

			if(input.mouse.click === true) {
				for(var iE = 0, c = game.mSpell.spells.length; iE < c; iE++) {
					if(this.onClickIcon(input.mouse.x, input.mouse.y, iE) == true) {
						var spell = game.mSpell.spells[iE];
						game.mSpell.entities.push(spell.summon());
						this.cooldown[iE] = Date.now();
						break;
					}
				}
			}

			this.animate();
		}

		this.animate = function() {

		}

		this.render = function() {

			for(var iE = 0, c = game.mSpell.spells.length; iE < c; iE++) {

				var coords = this.getIconCoords(iE);
				IM.drawImage(CTX, game.mSpell.spells[iE].img, coords.x, coords.y);

				if(interval(this.cooldown[iE], game.mSpell.spells[iE].cooldown) == false) {
					CTX.fillStyle = "rgba(0,0,0,.5)";
					CTX.fillRect(coords.x, coords.y, HudConf.spell.w, HudConf.spell.h);
				}
			}
		}
	// --- END CORE

	this.getIconCoords = function(id) {
		return {
			x : WIDTH/2 - (HudConf.spell.w*game.mSpell.spells.length)/2 + (HudConf.spell.w + HudConf.spell.margin)*id,
			y : HEIGHT - HudConf.spell.h - HudConf.margin
		};
	}

	this.onClickIcon = function(x, y, id) {
		var coords = this.getIconCoords(id);

		if(interval(this.cooldown[id], game.mSpell.spells[id].cooldown) == false) {
			return false;
		}

		return ((x >= coords.x && x <= coords.x+HudConf.spell.w) &&	(y >= coords.y && y <= coords.y+HudConf.spell.h));
	}
}